package com.xbongbong.paas.handle;


import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.product.pojo.vo.RelativeProductExplainVO;
import com.xbongbong.pro.weblist.pojo.ListOptionPackagePojo;
import com.xbongbong.saas.enums.business.MarketingActivityManagementEnum;
import com.xbongbong.saas.enums.dictionary.MarketingStatusEnum;
import com.xbongbong.saas.help.SaasListHelp;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 营销活动管理操作
 * @author jyh
 * @version v1.0
 * @date 2020/3/31 11:23
 * @since v1.0
 */
@Component
public class MarketingActivityManagementOptionHandle extends AbstractOptionHandle {

    @Resource
    private SaasListHelp saasListHelp;


    @Override
    public void setOptionsInExplain(FormDataListDTO formDataListDTO, List<FieldAttrEntity> explainList, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException {
        // 获取按钮的开关
        ListOptionPackagePojo listOptionPackagePojo = new ListOptionPackagePojo();
        listOptionPackagePojo.setNeedOption0(true);
        listOptionPackagePojo.setOnline(true);
        saasListHelp.setHeadList(explainList, listOptionPackagePojo, formDataListDTO.getSubBusinessType(),formDataListDTO.getBusinessType());
    }


    @Override
    public void setOptionsInData(FormDataListDTO formDataListDTO, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException {
        List<PaasFormDataEntityExt> dataList = paasFormDataEsListVO.getPaasFormDataESList();
        Map<String, FieldAttrEntity> explainMap = new HashMap<>(paasFormDataEsListVO.getHeadList().size());
        paasFormDataEsListVO.getHeadList().forEach(item->{
            explainMap.put(item.getAttr(), item);
        });
        ListOptionPackagePojo listOptionPackagePojo = new ListOptionPackagePojo();
        listOptionPackagePojo.setNeedOption0(true);

        for (PaasFormDataEntityExt item : dataList) {
            listOptionPackagePojo.setOnline(true);
            if (Objects.equals(item.getData().getString(MarketingActivityManagementEnum.STATUS.getAttr()), MarketingStatusEnum.OFFLINE.getName())) {
                listOptionPackagePojo.setOnline(false);
                listOptionPackagePojo.setFinish(true);
            }
            saasListHelp.setOptionValue(item, formDataListDTO, listOptionPackagePojo, formDataListDTO.getBusinessType(),
                    formDataListDTO.getSubBusinessType(), formDataListDTO.getListGroupId(), explainMap, new RelativeProductExplainVO());
        }
    }

    @Override
    public ListOptionPackagePojo getFirstOptionData(FormDataListDTO formDataListDTO, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException {
        return null;
    }


}
